﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Patin_task_1
{
    public class Team
    {
        public IFactory Factory { get; set; }
        List<IDeveloper> myList = new List<IDeveloper>();
        public override string ToString()
        {
            string myString = string.Empty;
            foreach (IDeveloper developer in myList)
            {
                myString += developer.Name + "\n";
            }
            return myString;
        }

        public void Add(IDeveloper dev)
        { 
            myList.Add(dev);
        }

        public void CreateTeam(int frontEndDeveloperCount, int backEndDeveloperCount)
        {
            if (Factory != null)
            {
                if (frontEndDeveloperCount > 0)
                    for (int i = 0; i < frontEndDeveloperCount; i++)
                    {
                        myList.Add(Factory.GetFrontEndDeveloper());
                    }
                if (backEndDeveloperCount > 0)
                    for (int i = 0; i < backEndDeveloperCount; i++)
                    {
                        myList.Add(Factory.GetBackEndDeveloper());
                    }
            }
            else
            {
                throw new InvalidOperationException("Invalid factory state. Initialize it");
            }
        }
    }
}
